package prastise;

import java.util.Stack;

class MyQueue {

    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public MyQueue() {
        this.stack1 = new Stack<>();
        this.stack2 = new Stack<>();
    }

    public void push(int x) {
        if(stack1.isEmpty()) {
            stack1.push(x);
            stack1.addAll(stack2);
            stack2.clear();
        } else {
            stack2.push(x);
            stack2.addAll(stack1);
            stack1.clear();
        }
    }
    
    public int pop() {
        if(empty()) {
            return 0;
        }
        return stack2.isEmpty() ? stack1.pop() : stack2.pop();
    }
    
    public int peek() {
        if(empty()) {
            return 0;
        }
        return stack2.isEmpty() ? stack1.peek() : stack2.peek();
    }
    
    public boolean empty() {
        return stack1.isEmpty() && stack2.empty();
    }
}